<template>
    <div class="wiper">
        <Filter title="库存" :items="items" :model="condition" />
        <Table :buttons="buttons" :columns="columns" :data="data" :pagination="condition" :rowKey="rowKey"/>
    </div>
</template>
<script>
import { message, Modal } from "ant-design-vue";
import Filter from "@/components/Filter";
import Table from "@/components/Table";
import { pager ,getAgv} from "@/api/inventory";
import {
    ColumnProps, FilterItems, FilterCondition
} from "./config";

export default {
    name: 'inventory',
    data() {
        return {
            items: FilterItems,
            data: [{}],
            rowKey: 'container',
            columns: ColumnProps,
          condition: {
            ...FilterCondition,
            onChange: (page, pageSize) => {
              this.condition.current = page;
              this.condition.pageSize = pageSize;
              this.load();
            }
          }
        }
    },
    components: {
        Filter,
        Table
    },
    mounted() {
        this.load();
        this.getAgv();
        this.items.filter(item=>item.key=='isEmpty')[0].data = [
            {value:0,label:'非空托'},
            {value:1,label:'空托盘'}
        ];
    },
    methods: {
        /**
         * 加载数据
         */
        load() {
            pager(this.condition).then(res => {
                this.data = res.data.rows;
                this.condition.total = res.data.total;
            })
        },
        /**
         * 跳转路由
         */
        goRoute(ids) {
            return new Promise((resolve, reject) => {
                if (ids.length == 0) {
                    return reject("至少要选择一条数据")
                }
                if (ids.length > 1) {
                    return reject("只能选择一条数据")
                }
                return resolve();
            })
        },
        /**
         * 刷新
         */
        // refresh(){
        //     this.load();
        // },

        _rename(list) {
            return list.map(item => {
                return { label: item.name, value: item.id, children: this._rename(item.children) }
            });
        },
        getAgv(){
            getAgv().then(res => {
                this.items.filter(item=>item.key=='agv')[0].data = 
                res.data.map(item => {
                    return {value: item.name, label:item.name}
                })
        ;
            })
        },

    }
}
</script>
<style></style>
